package com.huawei.hbase.data;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

public class DeleteData {
    public static void main(String[] args) throws IOException {
        //链接hbase
        Configuration conf = HBaseConfiguration.create();
        //这里的zookeeper地址要改为自己集群的zookeeper地址
        conf.set("hbase.zookeeper.quorum",
                "xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx");
        conf.set("hbase.zookeeper.property.clientPort", "2181");
        Connection connection = ConnectionFactory.createConnection(conf);

        Table hTable = connection.getTable(TableName.valueOf("users"));

        Delete delete = new Delete(Bytes.toBytes("row5"));
        delete.addColumn(Bytes.toBytes("f"),Bytes.toBytes("id"));
        //直接删除family,将所有row5的信息全部删除
        delete.addFamily(Bytes.toBytes("f"));
        hTable.delete(delete);
        System.out.println("删除成功");
    }
}